const querystring = require("querystring");
const MyModule = require('./controller/blog.js');
const MyModel = require('./model/responseModel');
//处理博客相关的路由,定义处理路由的逻辑
const handleBlogRoute = (req, res) => {
    const method = req.method;
    const url = req.url;
    req.path = url.split('?')[0] //问号分割取前半段
    //解析query
    req.query = querystring.parse(url.split('?')[1]);
    //如果请求如下就返回下面的结果，这个结果会保存到blogData
    if (method === 'GET' && req.path === '/api/blog/list') {
        const author = req.query.author || '';
        const keyword = req.query.keyword || '';
        let listData = MyModule.getList(author, keyword); //根据参数获取数
        console.log(listData);
        return new MyModel.SuccessModel(listData);

        return {
            message: '获取博客列表的接口...'
        }
    }
    if (method === 'GET' && req.path === '/api/blog/detail') {
        return {
            message: '获取博客详情的接口'
        }
    }
    if (method === 'POST' && req.path === '/api/blog/new') {
        return {
            message: '新建博客的接口'
        }
    }
    if (method === 'POST' && req.path === '/api/blog/update') {
        return {
            message: '更新博客的接口'
        }
    }
    if (method === 'POST' && req.path === '/api/blog/delete') {
        return {
            message: '删除博客的接口'
        }
    }


}
module.exports = handleBlogRoute;